#include "RC3DGameComponent.h"

RC3DGameComponent::RC3DGameComponent(void)
{
	position = XMFLOAT3(0,0,0);
	scale = XMFLOAT3(1,1,1);
	orientation = XMQuaternionIdentity();
}


RC3DGameComponent::~RC3DGameComponent(void)
{
}

void RC3DGameComponent::Update(float time)
{
	world = XMMatrixScaling(scale.x,scale.y,scale.z) * XMMatrixRotationQuaternion(orientation) * XMMatrixTranslation(position.x,position.y,position.z);
}

XMFLOAT3 RC3DGameComponent::getPosition()
{
	return position;
}
XMFLOAT3 RC3DGameComponent::getScale()
{
	return scale;
}
XMVECTOR RC3DGameComponent::getOrientation()
{
	return orientation;
}
XMMATRIX RC3DGameComponent::getWorld()
{
	return world;
}

void RC3DGameComponent::setPosition(XMFLOAT3 newPosition)
{
	position = newPosition;
}
void RC3DGameComponent::setScale(XMFLOAT3 newScale)
{
	scale = newScale;
}
void RC3DGameComponent::setOrientation(XMVECTOR newOrientation)
{
	orientation = newOrientation;
}

void RC3DGameComponent::Translate(XMFLOAT3 distance)
{
	XMVECTOR vDistance = XMLoadFloat3(&distance);

	XMFLOAT3 outPos;
	
	XMVECTOR v = XMVector3TransformCoord(vDistance, XMMatrixRotationQuaternion(orientation));

	XMVECTOR orgPos = XMLoadFloat3(&position);

	orgPos += v;

	XMStoreFloat3(&position,orgPos);
}
void RC3DGameComponent::Rotate(XMVECTOR axis, float angle) 
{
	orientation = XMQuaternionMultiply(XMQuaternionRotationAxis(axis,angle), orientation);
}

